package nil.ed.simulator.request.parser.impl;

import lombok.extern.slf4j.Slf4j;
import nil.ed.simulator.request.common.QQItem;
import nil.ed.simulator.request.parser.IParser;

import java.util.LinkedList;
import java.util.List;

/**
 * @author lidelin.
 */
@Slf4j
public class StandardParser implements IParser {
    @Override
    public List<QQItem> parse(String text) {
        List<QQItem> qqItemList = new LinkedList<>();
        String[] lines = text.split("\n");
        for (String line : lines) {
            String[] parts = line.split("----");
            if (parts.length != 2) {
                log.error("Parse error! line = {}, text = {}", line, text);
                continue;
            }
            QQItem qqItem = new QQItem();
            qqItem.setQq(parts[0]);
            qqItem.setPassword(parts[1]);
            qqItemList.add(qqItem);
        }
        return qqItemList;
    }
}
